home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Modules / getpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-10  |  17.1 KB  |  713 lines

  1. /* Return the initial module search path. */
  2.  
  3. #include "Python.h"
  4. #include "osdefs.h"
  5.  
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <string.h>
  9.  
  10. #include "protos/getpath.h"
  11.  
  12. #ifdef _AMIGA
  13. #include <proto/dos.h>
  14. #endif
  15.  
  16. #if HAVE_UNISTD_H
  17. #include <unistd.h>
  18. #endif /* HAVE_UNISTD_H */
  19.  
  20. #ifdef WITH_NEXT_FRAMEWORK
  21. #include <mach-o/dyld.h>
  22. #endif
  23.  
  24. /* Search in some common locations for the associated Python libraries.
  25.  *
  26.  * Two directories must be found, the platform independent directory
  27.  * (prefix), containing the common .py and .pyc files, and the platform
  28.  * dependent directory (exec_prefix), containing the shared library
  29.  * modules.  Note that prefix and exec_prefix can be the same directory,
  30.  * but for some installations, they are different.
  31.  *
  32.  * Py_GetPath() carries out separate searches for prefix and exec_prefix.
  33.  * Each search tries a number of different locations until a ``landmark''
  34.  * file or directory is found.  If no prefix or exec_prefix is found, a
  35.  * warning message is issued and the preprocessor defined PREFIX and
  36.  * EXEC_PREFIX are used (even though they will not work); python carries on
  37.  * as best as is possible, but most imports will fail.
  38.  *
  39.  * Before any searches are done, the location of the executable is
  40.  * determined.  If argv[0] has one or more slashs in it, it is used
  41.  * unchanged.  Otherwise, it must have been invoked from the shell's path,
  42.  * so we search $PATH for the named executable and use that.  If the
  43.  * executable was not found on $PATH (or there was no $PATH environment
  44.  * variable), the original argv[0] string is used.
  45.  *
  46.  * Next, the executable location is examined to see if it is a symbolic
  47.  * link.  If so, the link is chased (correctly interpreting a relative
  48.  * pathname if one is found) and the directory of the link target is used.
  49.  *
  50.  * Finally, argv0_path is set to the directory containing the executable
  51.  * (i.e. the last component is stripped).
  52.  *
  53.  * With argv0_path in hand, we perform a number of steps.  The same steps
  54.  * are performed for prefix and for exec_prefix, but with a different
  55.  * landmark.
  56.  *
  57.  * Step 1. Are we running python out of the build directory?  This is
  58.  * checked by looking for a different kind of landmark relative to
  59.  * argv0_path.  For prefix, the landmark's path is derived from the VPATH
  60.  * preprocessor variable (taking into account that its value is almost, but
  61.  * not quite, what we need).  For exec_prefix, the landmark is
  62.  * Modules/Setup.  If the landmark is found, we're done.
  63.  *
  64.  * For the remaining steps, the prefix landmark will always be
  65.  * lib/python$VERSION/string.py and the exec_prefix will always be
  66.  * lib/python$VERSION/lib-dynload, where $VERSION is Python's version
  67.  * number as supplied by the Makefile.  Note that this means that no more
  68.  * build directory checking is performed; if the first step did not find
  69.  * the landmarks, the assumption is that python is running from an
  70.  * installed setup.
  71.  *
  72.  * Step 2. See if the $PYTHONHOME environment variable points to the
  73.  * installed location of the Python libraries.  If $PYTHONHOME is set, then
  74.  * it points to prefix and exec_prefix.  $PYTHONHOME can be a single
  75.  * directory, which is used for both, or the prefix and exec_prefix
  76.  * directories separated by a colon.
  77.  *
  78.  * Step 3. Try to find prefix and exec_prefix relative to argv0_path,
  79.  * backtracking up the path until it is exhausted.  This is the most common
  80.  * step to succeed.  Note that if prefix and exec_prefix are different,
  81.  * exec_prefix is more likely to be found; however if exec_prefix is a
  82.  * subdirectory of prefix, both will be found.
  83.  *
  84.  * Step 4. Search the directories pointed to by the preprocessor variables
  85.  * PREFIX and EXEC_PREFIX.  These are supplied by the Makefile but can be
  86.  * passed in as options to the configure script.
  87.  *
  88.  * That's it!
  89.  *
  90.  * Well, almost.  Once we have determined prefix and exec_prefix, the
  91.  * preprocesor variable PYTHONPATH is used to construct a path.  Each
  92.  * relative path on PYTHONPATH is prefixed with prefix.  Then the directory
  93.  * containing the shared library modules is appended.  The environment
  94.  * variable $PYTHONPATH is inserted in front of it all.  Finally, the
  95.  * prefix and exec_prefix globals are tweaked so they reflect the values
  96.  * expected by other code, by stripping the "lib/python$VERSION/..." stuff
  97.  * off.  If either points to the build directory, the globals are reset to
  98.  * the corresponding preprocessor variables (so sys.prefix will reflect the
  99.  * installation location, even though sys.path points into the build
  100.  * directory).  This seems to make more sense given that currently the only
  101.  * known use of sys.prefix and sys.exec_prefix is for the ILU installation
  102.  * process to find the installed Python tree.
  103.  */
  104.  
  105. #ifndef VERSION
  106. #define VERSION "1.6"
  107. #endif
  108.  
  109. #ifndef VPATH
  110. #define VPATH "."
  111. #endif
  112.  
  113. #ifndef PREFIX
  114. #define PREFIX "/usr/local"
  115. #endif
  116.  
  117. #ifndef EXEC_PREFIX
  118. #define EXEC_PREFIX PREFIX
  119. #endif
  120.  
  121. #ifndef PYTHONPATH
  122. /* I know this isn't K&R C, but the Makefile specifies it anyway */
  123. #ifdef _AMIGA
  124. #define PYTHONPATH PREFIX "lib/python" VERSION ";" EXEC_PREFIX "lib/python" VERSION "/lib-dynload"
  125. #else /* !_AMIGA */
  126. #define PYTHONPATH PREFIX "/lib/python" VERSION ":" \
  127.           EXEC_PREFIX "/lib/python" VERSION "/lib-dynload"
  128. #endif
  129. #endif
  130.  
  131. #ifndef LANDMARK
  132. #define LANDMARK "string.py"
  133. #endif
  134.  
  135. static char prefix[MAXPATHLEN+1];
  136. static char exec_prefix[MAXPATHLEN+1];
  137. static char progpath[MAXPATHLEN+1];
  138. static char *module_search_path = NULL;
  139. static char lib_python[20]; /* Dynamically set to "lib/python" VERSION */
  140.  
  141. #ifdef _AMIGA
  142. /* determine full program path */
  143. extern void Py_GetArgcArgv Py_PROTO((int *argc, char ***argv));    /* in main.c */
  144.  
  145. static const char *fullprogpath(void)
  146. {
  147.     static char path[MAXPATHLEN*2];
  148.     static char prog[MAXPATHLEN];
  149.  
  150.     BPTR dir;
  151.  
  152.     extern BOOL from_WB;    /* in main.c */
  153.  
  154.     // If the program name contains ':' or '/' it's not in the user's path
  155.     // and probably set by using Py_SetProgramName. In that case, just
  156.     // use this. If it exists!
  157.     strcpy(path,Py_GetProgramName());
  158.     if(strchr(path,':') || strchr(path,'/'))
  159.     {
  160.         if(!isxfile(path))
  161.         {
  162.             // Error; the specified file does not exist or is no exe
  163.             path[0]='\0';
  164.         }
  165.         return path;
  166.     }
  167.  
  168.     // Construct the full path of our executable program.
  169.     if(from_WB)
  170.     {
  171.         /* We're launced from WB, GetProgramName() won't work */
  172.         /* Use WB's argv[0] as the executable path */
  173.         int argc;
  174.         char **argv;
  175.         Py_GetArgcArgv(&argc, &argv);
  176.         if(argc>0)
  177.             strcpy(path,argv[0]);
  178.         else
  179.             strcpy(path,"!error!");
  180.     }
  181.     else
  182.     {
  183.         /* Launced from CLI, use GetProgramName */
  184.  
  185.         /* However, first check if the specified name exists */
  186.         if(!isxfile(path))
  187.         {
  188.             path[0]='\0';
  189.             return path;
  190.         }
  191.  
  192.         path[0]=0;
  193.         if(dir=GetProgramDir())
  194.         {
  195.             (void)NameFromLock(dir,path,MAXPATHLEN);
  196.             if(!GetProgramName(prog,MAXPATHLEN))    // this is a dos.library function!
  197.                 strcpy(prog,"!error!");
  198.             if(!AddPart(path,prog,MAXPATHLEN*2))
  199.                 strcpy(path,"!error!");
  200.         }    
  201.     }
  202.     return path;
  203. }
  204.  
  205. static void reduce( char *dir)
  206. {
  207.     int i = strlen(dir);
  208.     if(i>0 && dir[i-1]==':') dir[--i]=0;
  209.     while (i > 0 && dir[i] != SEP && dir[i] != ':') --i;
  210.     if(dir[i]!=':') dir[i] = '\0';
  211.     else dir[i+1]='\0';
  212. }
  213.  
  214. #else /*! AMIGA */
  215.  
  216. static void
  217. reduce(dir)
  218.     char *dir;
  219. {
  220.     int i = strlen(dir);
  221.     while (i > 0 && dir[i] != SEP)
  222.         --i;
  223.     dir[i] = '\0';
  224. }
  225.  
  226. #endif
  227.  
  228. #ifndef S_ISREG
  229. #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
  230. #endif
  231.  
  232. #ifndef S_ISDIR
  233. #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
  234. #endif
  235.  
  236. static int
  237. isfile(filename)        /* Is file, not directory */
  238.     char *filename;
  239. {
  240.     struct stat buf;
  241.     if (stat(filename, &buf) != 0)
  242.         return 0;
  243.     if (!S_ISREG(buf.st_mode))
  244.         return 0;
  245.     return 1;
  246. }
  247.  
  248.  
  249. static int
  250. ismodule(filename)        /* Is module -- check for .pyc/.pyo too */
  251.     char *filename;
  252. {
  253.     if (isfile(filename))
  254.         return 1;
  255.  
  256.     /* Check for the compiled version of prefix. */
  257.     if (strlen(filename) < MAXPATHLEN) {
  258.         strcat(filename, Py_OptimizeFlag ? "o" : "c");
  259.         if (isfile(filename))
  260.             return 1;
  261.     }
  262.     return 0;
  263. }
  264.  
  265.  
  266. static int
  267. isxfile(filename)        /* Is executable file */
  268.     char *filename;
  269. {
  270.     struct stat buf;
  271.     if (stat(filename, &buf) != 0)
  272.         return 0;
  273.     if (!S_ISREG(buf.st_mode))
  274.         return 0;
  275.     if ((buf.st_mode & 0111) == 0)
  276.         return 0;
  277.     return 1;
  278. }
  279.  
  280.  
  281. static int
  282. isdir(filename)            /* Is directory */
  283.     char *filename;
  284. {
  285.     struct stat buf;
  286.     if (stat(filename, &buf) != 0)
  287.         return 0;
  288.     if (!S_ISDIR(buf.st_mode))
  289.         return 0;
  290.     return 1;
  291. }
  292.  
  293.  
  294. #ifdef _AMIGA
  295. #define joinpath(buffer,stuff) AddPart(buffer,stuff,MAXPATHLEN)
  296. #else
  297. static void
  298. joinpath(buffer, stuff)
  299.     char *buffer;
  300.     char *stuff;
  301. {
  302.     int n, k;
  303.     if (stuff[0] == SEP)
  304.         n = 0;
  305.     else {
  306.         n = strlen(buffer);
  307.         if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN)
  308.             buffer[n++] = SEP;
  309.     }
  310.     k = strlen(stuff);
  311.     if (n + k > MAXPATHLEN)
  312.         k = MAXPATHLEN - n;
  313.     strncpy(buffer+n, stuff, k);
  314.     buffer[n+k] = '\0';
  315. }
  316. #endif
  317.  
  318.  
  319. static int
  320. search_for_prefix(argv0_path, home)
  321.     char *argv0_path;
  322.     char *home;
  323. {
  324.     int n;
  325.     char *vpath;
  326.  
  327.     /* Check to see if argv[0] is in the build directory */
  328.     strcpy(prefix, argv0_path);
  329.     joinpath(prefix, "Modules/Setup");
  330.     if (isfile(prefix)) {
  331.         /* Check VPATH to see if argv0_path is in the build directory.
  332.          * Complication: the VPATH passed in is relative to the
  333.          * Modules build directory and points to the Modules source
  334.          * directory; we need it relative to the build tree and
  335.          * pointing to the source tree.  Solution: chop off a leading
  336.          * ".." (but only if it's there -- it could be an absolute
  337.          * path) and chop off the final component (assuming it's
  338.          * "Modules").
  339.          */
  340.         vpath = VPATH;
  341.         if (vpath[0] == '.' && vpath[1] == '.' && vpath[2] == '/')
  342.             vpath += 3;
  343.         strcpy(prefix, argv0_path);
  344.         joinpath(prefix, vpath);
  345.         reduce(prefix);
  346.         joinpath(prefix, "Lib");
  347.         joinpath(prefix, LANDMARK);
  348.         if (ismodule(prefix))
  349.             return -1;
  350.     }
  351.  
  352.     if (home) {
  353.         /* Check $PYTHONHOME */
  354.         char *delim;
  355.         strcpy(prefix, home);
  356.         delim = strchr(prefix, DELIM);
  357.         if (delim)
  358.             *delim = '\0';
  359.         joinpath(prefix, lib_python);
  360.         joinpath(prefix, LANDMARK);
  361.         if (ismodule(prefix))
  362.             return 1;
  363.     }
  364.  
  365.     /* Search from argv0_path, until root is found */
  366.     strcpy(prefix, argv0_path);
  367.     do {
  368.         n = strlen(prefix);
  369.         joinpath(prefix, lib_python);
  370.         joinpath(prefix, LANDMARK);
  371.         if (ismodule(prefix))
  372.             return 1;
  373.         prefix[n] = '\0';
  374.         reduce(prefix);
  375.     } while (prefix[0]);
  376.  
  377.     /* Look at configure's PREFIX */
  378.     strcpy(prefix, PREFIX);
  379.     joinpath(prefix, lib_python);
  380.     joinpath(prefix, LANDMARK);
  381.     if (ismodule(prefix))
  382.         return 1;
  383.  
  384.     /* Fail */
  385.     return 0;
  386. }
  387.  
  388.  
  389. static int
  390. search_for_exec_prefix(argv0_path, home)
  391.     char *argv0_path;
  392.     char *home;
  393. {
  394.     int n;
  395.  
  396.     /* Check to see if argv[0] is in the build directory */
  397.     strcpy(exec_prefix, argv0_path);
  398.     joinpath(exec_prefix, "Modules/Setup");
  399.     if (isfile(exec_prefix)) {
  400.         reduce(exec_prefix);
  401.         return -1;
  402.     }
  403.  
  404.     if (home) {
  405.         /* Check $PYTHONHOME */
  406.         char *delim;
  407.         delim = strchr(home, DELIM);
  408.         if (delim)
  409.             strcpy(exec_prefix, delim+1);
  410.         else
  411.             strcpy(exec_prefix, home);
  412.         joinpath(exec_prefix, lib_python);
  413.         joinpath(exec_prefix, "lib-dynload");
  414.         if (isdir(exec_prefix))
  415.             return 1;
  416.     }
  417.  
  418.     /* Search from argv0_path, until root is found */
  419.     strcpy(exec_prefix, argv0_path);
  420.     do {
  421.         n = strlen(exec_prefix);
  422.         joinpath(exec_prefix, lib_python);
  423.         joinpath(exec_prefix, "lib-dynload");
  424.         if (isdir(exec_prefix))
  425.             return 1;
  426.         exec_prefix[n] = '\0';
  427.         reduce(exec_prefix);
  428.     } while (exec_prefix[0]);
  429.  
  430.     /* Look at configure's EXEC_PREFIX */
  431.     strcpy(exec_prefix, EXEC_PREFIX);
  432.     joinpath(exec_prefix, lib_python);
  433.     joinpath(exec_prefix, "lib-dynload");
  434.     if (isdir(exec_prefix))
  435.         return 1;
  436.  
  437.     /* Fail */
  438.     return 0;
  439. }
  440.  
  441.  
  442. static void
  443. calculate_path()
  444. {
  445.     extern char *Py_GetProgramName();
  446.  
  447.     static char delimiter[2] = {DELIM, '\0'};
  448.     static char separator[2] = {SEP, '\0'};
  449.     char *pythonpath = PYTHONPATH;
  450.     char *rtpypath = getenv("PYTHONPATH");
  451.     char *home = Py_GetPythonHome();
  452. #ifndef _AMIGA
  453.     char *path = getenv("PATH");
  454.     char *prog = Py_GetProgramName();
  455. #endif
  456.     char argv0_path[MAXPATHLEN+1];
  457.     int pfound, efound; /* 1 if found; -1 if found build directory */
  458.     char *buf;
  459.     int bufsz;
  460.     int prefixsz;
  461.     char *defpath = pythonpath;
  462. #ifdef WITH_NEXT_FRAMEWORK
  463.         NSModule pythonModule;
  464. #endif
  465.     
  466. #ifdef WITH_NEXT_FRAMEWORK
  467.         pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
  468.     /* Use dylib functions to find out where the framework was loaded from */
  469.         buf = NSLibraryNameForModule(pythonModule);
  470.         if (buf != NULL) {
  471.             /* We're in a framework. */
  472.             strcpy(progpath, buf);
  473.  
  474.             /* Frameworks have support for versioning */
  475.             strcpy(lib_python, "lib");
  476.         } else {
  477.             /* If we're not in a framework, fall back to the old way (even though NSNameOfModule() probably does the same thing.) */
  478. #endif
  479.     
  480.     /* Initialize this dynamically for K&R C */
  481.     sprintf(lib_python, "lib/python%s", VERSION);
  482.  
  483. #ifdef _AMIGA
  484.     strcpy(progpath,fullprogpath());
  485. #else /* !_AMIGA */
  486.     /* If there is no slash in the argv0 path, then we have to
  487.      * assume python is on the user's $PATH, since there's no
  488.      * other way to find a directory to start the search from.  If
  489.      * $PATH isn't exported, you lose.
  490.      */
  491.     if (strchr(prog, SEP))
  492.         strcpy(progpath, prog);
  493.     else if (path) {
  494.         while (1) {
  495.             char *delim = strchr(path, DELIM);
  496.  
  497.             if (delim) {
  498.                 int len = delim - path;
  499.                 strncpy(progpath, path, len);
  500.                 *(progpath + len) = '\0';
  501.             }
  502.             else
  503.                 strcpy(progpath, path);
  504.  
  505.             joinpath(progpath, prog);
  506.             if (isxfile(progpath))
  507.                 break;
  508.  
  509.             if (!delim) {
  510.                 progpath[0] = '\0';
  511.                 break;
  512.             }
  513.             path = delim + 1;
  514.         }
  515.     }
  516.     else
  517.         progpath[0] = '\0';
  518. #ifdef WITH_NEXT_FRAMEWORK
  519.         }
  520. #endif
  521. #endif /* !_AMIGA */
  522.     strcpy(argv0_path, progpath);
  523.     
  524. #if HAVE_READLINK
  525.     {
  526.         char tmpbuffer[MAXPATHLEN+1];
  527.         int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN);
  528.         while (linklen != -1) {
  529.             /* It's not null terminated! */
  530.             tmpbuffer[linklen] = '\0';
  531. #ifdef _AMIGA
  532.             if (NULL==strchr(tmpbuffer,':'))
  533. #else
  534.             if (tmpbuffer[0] == SEP)
  535. #endif
  536.                 strcpy(argv0_path, tmpbuffer);
  537.             else {
  538.                 /* Interpret relative to progpath */
  539.                 reduce(argv0_path);
  540.                 joinpath(argv0_path, tmpbuffer);
  541.             }
  542.             linklen = readlink(argv0_path, tmpbuffer, MAXPATHLEN);
  543.         }
  544.     }
  545. #endif /* HAVE_READLINK */
  546.  
  547.     reduce(argv0_path);
  548.  
  549.     if (!(pfound = search_for_prefix(argv0_path, home))) {
  550.         if (!Py_FrozenFlag)
  551.         fprintf(stderr,
  552.            "Could not find platform independent libraries <prefix>\n");
  553.         strcpy(prefix, PREFIX);
  554.         joinpath(prefix, lib_python);
  555.     }
  556.     else
  557.         reduce(prefix);
  558.     
  559.     if (!(efound = search_for_exec_prefix(argv0_path, home))) {
  560.         if (!Py_FrozenFlag)
  561.         fprintf(stderr,
  562.         "Could not find platform dependent libraries <exec_prefix>\n");
  563.         strcpy(exec_prefix, EXEC_PREFIX);
  564.         joinpath(exec_prefix, "lib/lib-dynload");
  565.     }
  566.     /* If we found EXEC_PREFIX do *not* reduce it!  (Yet.) */
  567.  
  568.     if ((!pfound || !efound) && !Py_FrozenFlag)
  569.         fprintf(stderr,
  570.          "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n");
  571.  
  572.     /* Calculate size of return buffer.
  573.      */
  574.     bufsz = 0;
  575.  
  576.     if (rtpypath)
  577.         bufsz += strlen(rtpypath) + 1;
  578.  
  579.     prefixsz = strlen(prefix) + 1;
  580.  
  581.     while (1) {
  582.         char *delim = strchr(defpath, DELIM);
  583.  
  584. #ifdef _AMIGA
  585.         if (NULL==strchr(defpath,':'))
  586. #else
  587.         if (defpath[0] != SEP)
  588. #endif
  589.             /* Paths are relative to prefix */
  590.             bufsz += prefixsz;
  591.  
  592.         if (delim)
  593.             bufsz += delim - defpath + 1;
  594.         else {
  595.             bufsz += strlen(defpath) + 1;
  596.             break;
  597.         }
  598.         defpath = delim + 1;
  599.     }
  600.  
  601.     bufsz += strlen(exec_prefix) + 1;
  602.  
  603.     /* This is the only malloc call in this file */
  604.     buf = PyMem_Malloc(bufsz);
  605.  
  606.     if (buf == NULL) {
  607.         /* We can't exit, so print a warning and limp along */
  608.         fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n");
  609.         fprintf(stderr, "Using default static PYTHONPATH.\n");
  610.         module_search_path = PYTHONPATH;
  611.     }
  612.     else {
  613.         /* Run-time value of $PYTHONPATH goes first */
  614.         if (rtpypath) {
  615.             strcpy(buf, rtpypath);
  616.             strcat(buf, delimiter);
  617.         }
  618.         else
  619.             buf[0] = '\0';
  620.  
  621.         /* Next goes merge of compile-time $PYTHONPATH with
  622.          * dynamically located prefix.
  623.          */
  624.         defpath = pythonpath;
  625.         while (1) {
  626.             char *delim = strchr(defpath, DELIM);
  627.  
  628. #ifdef _AMIGA
  629.             if (NULL==strchr(defpath,':')) {
  630. #else
  631.             if (defpath[0] != SEP) {
  632. #endif
  633.                 strcat(buf, prefix);
  634.                 strcat(buf, separator);
  635.             }
  636.  
  637.             if (delim) {
  638.                 int len = delim - defpath + 1;
  639.                 int end = strlen(buf) + len;
  640.                 strncat(buf, defpath, len);
  641.                 *(buf + end) = '\0';
  642.             }
  643.             else {
  644.                 strcat(buf, defpath);
  645.                 break;
  646.             }
  647.             defpath = delim + 1;
  648.         }
  649.         strcat(buf, delimiter);
  650.  
  651.         /* Finally, on goes the directory for dynamic-load modules */
  652.         strcat(buf, exec_prefix);
  653.  
  654.         /* And publish the results */
  655.         module_search_path = buf;
  656.     }
  657.  
  658.     /* Reduce prefix and exec_prefix to their essence,
  659.      * e.g. /usr/local/lib/python1.5 is reduced to /usr/local.
  660.      * If we're loading relative to the build directory,
  661.      * return the compiled-in defaults instead.
  662.      */
  663.     if (pfound > 0) {
  664.         reduce(prefix);
  665.         reduce(prefix);
  666.     }
  667.     else
  668.         strcpy(prefix, PREFIX);
  669.  
  670.     if (efound > 0) {
  671.         reduce(exec_prefix);
  672.         reduce(exec_prefix);
  673.         reduce(exec_prefix);
  674.     }
  675.     else
  676.         strcpy(exec_prefix, EXEC_PREFIX);
  677. }
  678.  
  679.  
  680. /* External interface */
  681.  
  682. char *
  683. Py_GetPath()
  684. {
  685.     if (!module_search_path)
  686.         calculate_path();
  687.     return module_search_path;
  688. }
  689.  
  690. char *
  691. Py_GetPrefix()
  692. {
  693.     if (!module_search_path)
  694.         calculate_path();
  695.     return prefix;
  696. }
  697.  
  698. char *
  699. Py_GetExecPrefix()
  700. {
  701.     if (!module_search_path)
  702.         calculate_path();
  703.     return exec_prefix;
  704. }
  705.  
  706. char *
  707. Py_GetProgramFullPath()
  708. {
  709.     if (!module_search_path)
  710.         calculate_path();
  711.     return progpath;
  712. }
  713.